package com.xk857.article.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xk857.entities.Category;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author CV大魔王
 * @Description 文章模块Mapper
 * @date 2021/2/21 11:10
 */
public interface CategoryMapper extends BaseMapper<Category> {

    /**
     * 查询所有正常状态的模块及模块下的所有知识点
     *
     * @return
     */
    @Select("SELECT id,name,remark FROM xk857_category WHERE `status`= 1 ORDER BY sort ")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "remark", property = "remark"),
            @Result(column = "id",property = "labelList", javaType = List.class,many = @Many(select = "com.xk857.article.mapper.LabelMapper.findListByCategoryId"))
    })
    List<Category> findCategoryAndLabel();


    @Select("SELECT name FROM xk857_category where id = #{id}")
    String findCategoryNameByLabelId(String id);
}
